package com.dao.impl;

import com.dao.BrandDao;
import com.dao.ProductTypeDao;
import com.pojo.Brand;
import com.pojo.PageBean;
import com.utils.JDBCUtil;

import java.util.List;

public class BrandDaoImpl implements BrandDao {

    /**
     * 查询所有方法
     * @param start
     * @param limit
     * @return
     */
    @Override
    public List<Brand> findAll(int start, int limit) {
        List<Brand> list = JDBCUtil.queryList(Brand.class, "select * from s_brand limit ?,?", start, limit);
        return list;
    }

    /**
     * 新增方法
     * @param brand
     * @return
     */
    @Override
    public int addBrand(Brand brand) {
        return JDBCUtil.update("insert into s_brand values(?,?,?,?)",brand.getId(),brand.getBrandName(),brand.getBrandType(),brand.getBrandImg());
    }

    /**
     * 修改方法
     * @param brand
     * @return
     */
    @Override
    public int updateBrand(Brand brand) {
        return JDBCUtil.update("update s_brand set brand_name = ?,brand_type=?,brand_img = ? where id = ?",brand.getBrandName(),brand.getBrandType(),brand.getBrandImg(),brand.getId());
    }

    /**
     * 删除方法
     * @param id
     * @return
     */
    @Override
    public int deleteBrand(String id) {
        return JDBCUtil.update("delete from s_brand where id = ?",id);
    }

    /**
     * 根据ID获取数据方法
     * @param id
     * @return
     */
    @Override
    public Brand findByID(String id) {
        return JDBCUtil.queryOne(Brand.class,"select * from s_brand where id = ?",id);
    }

    /**
     * 获取到总行数
     * @return
     */
    @Override
    public int  findCOunt() {
        return JDBCUtil.queryCount("select count(*) from s_brand");
    }

    /**
     * 根据名字查询数据
     * @param name
     * @return
     */
    @Override
    public Brand findByName(String name) {
        return JDBCUtil.queryOne(Brand.class,"select * from s_brand where brand_name = ?",name);
    }


    /**
     * 根据productType获取brand
     * @param brandType
     * @return
     */
    @Override
    public List<Brand> findByBrandType(String brandType) {
        return JDBCUtil.queryList(Brand.class,"select * from s_brand where brand_type = ?",brandType);
    }


}
